package com.changgou.seckill.mq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 超时队列（延时队列）  负责赞数储存数据
 * 真正监听的队列
 * 交换机
 */
@Configuration
public class QueueConfig {

    //延时队列--》暂时储存数据
    public Queue delayMessageQueue(){
    return QueueBuilder.durable("delayMessageQueue")
            .withArgument("x-dead-letter-exchange",exchange())   //当前队列的消息一旦过期，则进入到死信队列交换机
            .withArgument("x-dead-letter-routing-key",seckillQueue())  //将死信队列的数据路由到指定队列中
            .build();
    }

    /**
     * 消息发送队列  Q2
     * @return
     */
    @Bean
    public Queue seckillQueue(){
        return new Queue("seckillQueue");
    }

    //交换机
    @Bean
    public Exchange exchange(){
        return new DirectExchange("seckillExchange");
    }
    //队列绑定交换机
    @Bean
    public Binding seckillQueueBindindExchange(Queue seckillQueue ,Exchange exchange){
        return BindingBuilder.bind(seckillQueue).to(exchange).with("seckillQueue").noargs();
    }
}
